home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / BCCollec / Structs / Collects / BCColl.h < prev    next >
Encoding:
Text File  |  1994-04-21  |  2.6 KB  |  114 lines  |  [TEXT/MPS ]

  1. //  The C++ Booch Components (Version 2.1)
  2. //  (C) Copyright 1990-1993 Grady Booch. All Rights Reserved.
  3. //
  4. //  BCColl.h
  5. //
  6. //  This file contains the declaration of the collection abstract base class
  7. //  and its iterators.
  8.  
  9. #ifndef BCCOLL_H
  10. #define BCCOLL_H 1
  11.  
  12. #include "BCType.h"
  13.  
  14. template<class Item>
  15. class BC_TCollectionActiveIterator;
  16.  
  17. template<class Item>
  18. class BC_TCollectionPassiveIterator;
  19.  
  20. template<class Item, class Structure>
  21. class BC_TPersist;
  22.  
  23. // Collection abstract base class
  24.  
  25. template<class Item>
  26. class BC_TCollection {
  27. public:
  28.  
  29.   BC_TCollection();
  30.   BC_TCollection(const BC_TCollection<Item>&);
  31.   virtual ~BC_TCollection();
  32.  
  33.   virtual BC_TCollection<Item>& operator=(const BC_TCollection<Item>&);
  34.   virtual BC_Boolean operator==(const BC_TCollection<Item>&) const;
  35.   BC_Boolean operator!=(const BC_TCollection<Item>&) const;
  36.   virtual const Item& operator[](BC_Index) const = 0;
  37.   virtual Item& operator[](BC_Index) = 0;
  38.  
  39.   virtual void Clear() = 0;
  40.   virtual void Insert(const Item&) = 0;
  41.   virtual void Insert(const Item&, BC_Index before) = 0;
  42.   virtual void Append(const Item&) = 0;
  43.   virtual void Append(const Item&, BC_Index after) = 0;
  44.   virtual void Remove(BC_Index at) = 0;
  45.   virtual void Replace(BC_Index at, const Item&) = 0;
  46.  
  47.   virtual BC_Index Length() const = 0;
  48.   virtual BC_Boolean IsEmpty() const = 0;
  49.   virtual const Item& First() const = 0;
  50.   virtual Item& First() = 0;
  51.   virtual const Item& Last() const = 0;
  52.   virtual Item& Last() = 0;
  53.   virtual BC_ExtendedIndex Location(const Item&) const = 0;
  54.  
  55. protected:
  56.  
  57.   virtual void Purge() = 0;
  58.   virtual void Add(const Item&) = 0;
  59.   virtual BC_Index Cardinality() const = 0;
  60.   virtual const Item& ItemAt(BC_Index) const = 0;
  61.  
  62.   virtual void Lock();
  63.   virtual void Unlock();
  64.  
  65. private:
  66.  
  67.   friend class BC_TCollectionActiveIterator<Item>;
  68.   friend class BC_TCollectionPassiveIterator<Item>;
  69.  
  70.   friend class BC_TPersist<Item, BC_TCollection<Item> >;
  71.  
  72. };
  73.  
  74. // Collection iterators
  75.  
  76. template <class Item>
  77. class BC_TCollectionActiveIterator {
  78. public:
  79.  
  80.   BC_TCollectionActiveIterator(const BC_TCollection<Item>&); 
  81.   ~BC_TCollectionActiveIterator();
  82.   
  83.   void Reset();
  84.   BC_Boolean Next();
  85.  
  86.   BC_Boolean IsDone() const;
  87.   const Item* CurrentItem() const;
  88.   Item* CurrentItem();
  89.   
  90. protected:
  91.  
  92.   const BC_TCollection<Item>& fCollection;
  93.   BC_ExtendedIndex fIndex;
  94.   
  95. };
  96.  
  97. template <class Item>
  98. class BC_TCollectionPassiveIterator {
  99. public:
  100.  
  101.   BC_TCollectionPassiveIterator(const BC_TCollection<Item>&);
  102.   ~BC_TCollectionPassiveIterator();
  103.   
  104.   BC_Boolean Apply(BC_Boolean (*)(const Item&));
  105.   BC_Boolean Apply(BC_Boolean (*)(Item&));
  106.   
  107. protected:
  108.  
  109.   const BC_TCollection<Item>& fCollection;
  110.  
  111. };
  112.  
  113. #endif
  114.